﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoldierAttackState : ISoldierState {
    public SoldierAttackState(SoldierFSMSystem fsm,Character character) : base(fsm,character)
    {
        m_stateID = SoldierStateID.Attack;
    }
    private float attacktime = 1f;
    private float attacktimer = 1f;
    public override void Act(List<Character> targets)
    {
        if (targets == null || targets.Count > 0) return;
        attacktimer += Time.deltaTime;
        if (attacktimer > attacktime)
        {
            attacktimer = 0f;
            m_character.Attack(targets[0]);
        }
    }

    public override void Reason(List<Character> targets)
    {
        if (targets == null || targets.Count > 0)
        {
            m_FSM.PerformTransition(SoldierTrasition.LostEnemy);
            return;
        }
        float distance = Vector3.Distance(targets[0].Position, m_character.Position);
        if (distance > m_character.AttackRange)
        {
            m_FSM.PerformTransition(SoldierTrasition.CanSeeEnemey);
        }
    }


}
